<?php
/**
 * Created by PhpStorm.
 * User: G
 * Date: 2021/3/23
 * Time: 下午2:12
 */

namespace app\api\controller;

use app\admin\model\profit\AdsApply;
use app\common\controller\Api;
use think\Exception;

class Ads extends Api
{
    // 无需登录的接口,*表示全部
    protected $noNeedLogin = [''];
    // 无需鉴权的接口,*表示全部
    protected $noNeedRight = ['*'];

    /**
     * 广告合作申请
     * @author G
     * @date 2021-03-23 下午2:19
     */
    public function apply()
    {
        try {

            $name = $this->request->post('name', '');
            $mobile = $this->request->post('mobile', '');
            $price = $this->request->post('price', '');
            $uid = $this->auth->getUser()->id;

            $shop_id = $this->request->post('shop_id', 0);
            $remarks = $this->request->post('remarks', '');

            if (!$name || !$mobile) {
                throw new Exception('参数缺失');
            }
            $insert_res = AdsApply::insert([
                'uid' => $uid,
                'name' => $name,
                'mobile' => $mobile,
                'company' => $this->request->post('company', ''),
                'desc' => $this->request->post('desc', ''),
                'price' => $price,
                'status' => 0,
                'shop_id' => $shop_id,
                'remarks' => $remarks,
                'createtime' => time(),
                'updatetime' => time()
            ]);

            if (!$insert_res) {
                throw new Exception('申请失败');
            }
        } catch (Exception $e) {
            $this->error($e->getMessage());
        }

        $this->success('申请成功', []);

    }
}